package com.ruoyi.web.controller.Tour;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TourType;
import com.ruoyi.system.service.ITourTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类别管理Controller
 *
 * @author once
 * @date 2020-10-02
 */
@RestController
@RequestMapping("/Tour/type")
public class TourTypeController extends BaseController
{
    @Autowired
    private ITourTypeService tourTypeService;

    /**
     * 查询类别管理列表
     */
    @PreAuthorize("@ss.hasPermi('Tour:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(TourType tourType)
    {
        startPage();
        List<TourType> list = tourTypeService.selectTourTypeList(tourType);
        return getDataTable(list);
    }

    /**
     * 导出类别管理列表
     */
    @PreAuthorize("@ss.hasPermi('Tour:type:export')")
    @Log(title = "类别管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TourType tourType)
    {
        List<TourType> list = tourTypeService.selectTourTypeList(tourType);
        ExcelUtil<TourType> util = new ExcelUtil<TourType>(TourType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 获取类别管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('Tour:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return AjaxResult.success(tourTypeService.selectTourTypeById(typeId));
    }

    /**
     * 新增类别管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:type:add')")
    @Log(title = "类别管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TourType tourType)
    {
        return toAjax(tourTypeService.insertTourType(tourType));
    }

    /**
     * 修改类别管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:type:edit')")
    @Log(title = "类别管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TourType tourType)
    {
        return toAjax(tourTypeService.updateTourType(tourType));
    }

    /**
     * 删除类别管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:type:remove')")
    @Log(title = "类别管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(tourTypeService.deleteTourTypeByIds(typeIds));
    }
}
